package com.yvdelx.cyclowomen.utility;

import android.app.Activity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Class utility for activities
 * Created by ydelvaux on 22/02/14.
 */
public class ActivityUtility {

    /*
     * Constant Activity number
     */
    public static int CST_CALENDAR_ACTIVITY = 1;

    @SuppressWarnings("unused")
    public static int CST_DAY_CONSULTATION = 2;

    @SuppressWarnings("unused")
    public static int CST_DAY_MODIFICATION = 3;

    public static int CST_PROFILE_ACTIVITY = 4;

    @SuppressWarnings("unused")
    public static int CST_KILL_VALUE = 0;


    /*
     * List of activities which not closed
     */
    private static List<Activity> history = new ArrayList<Activity>();

    /**
     * Modify the activity title to add the date
     * @param act Activity
     * @param date Date
     */
    public static void setNewTitle(Activity act, Date date){
        CharSequence title = act.getTitle();
        String newTitle = title.toString() + " " + DateUtility.dateToString(date);
        act.setTitle(newTitle);
    }

    /**
     * Add activity to the navigation history
     * @param activity Activity
     */
    public static void addActivity(Activity activity){
        history.add(activity);
    }

    /**
     * Close all activities (close the app properly)
     */
    public static void closeActivities(){
        for(Activity activity : history){
            activity.finish();
        }
    }

    /**
     * Close all activities in the list in param
     * @param activities List<Activity>
     */
    public static void closeActivities(List<Activity> activities){
        // Delete all references of activities in the history list
        history.removeAll(activities);
        // Close activities of the list in param
        for(Activity activity : activities){
            activity.finish();
        }
    }

    /**
     * Close an activity and remove it in the history list
     * @param activity Activity
     */
    public static void closeActivity(Activity activity) {
        history.remove(activity);
        activity.finish();
    }
}
